<?php
    require_once "config.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $id = $_POST['id'];
        $is_vip = $_POST['is_vip'];
        $invite_code = $_POST['invite_code'];
        $params = array(
            'avatar' => $_POST['avatar'],
            'username' => $_POST['username'],
            'intro' => $_POST['intro'],
            'mobile' => $_POST['mobile'],
            'wx_img' => $_POST['wx_img'],
            'sort' => $_POST['sort'],

        );
        if($is_vip == 3 || !empty($invite_code)){
            $params['shop_add'] = $_POST['shop_add'];
            $params['shop_lng'] = $_POST['shop_lng'];
            $params['shop_lat'] = $_POST['shop_lat'];
            $params['shop_spot'] = $_POST['shop_spot'];
            $params['shop_spot_ratio'] = $_POST['shop_spot_ratio'];
            $params['praise_num'] = $_POST['praise_num'];
            $params['praise_img'] = $_POST['praise_img'];
            $params['praise_award'] = $_POST['praise_award'];
            $params['shop_yyzz'] = $_POST['shop_yyzz'];
            $params['shop_hygiene'] = $_POST['shop_hygiene'];
            $params['shop_bank'] = $_POST['shop_bank'];
            $params['shop_just'] = $_POST['shop_just'];
            $params['shop_back'] = $_POST['shop_back'];
            $params['qq_email'] = $_POST['qq_email'];
            $params['shop_doorway'] = $_POST['shop_doorway'];
            $params['shop_images'] = $_POST['shop_images'];
            $params['shop_bank_add'] = $_POST['shop_bank_add'];
            if(empty($params['shop_add']) || empty($params['shop_yyzz'])){
                $result['status'] = 'n';
                $result['info'] = '商铺地址与营业执照为必填项，请重新输入';
                exit(json_encode($result));
            }
        }
        if(empty($params['avatar']) || empty($params['username']) || empty($params['username'])){
            $result['status'] = 'n';
            $result['info'] = '以上带*号属性为必填项';
            exit(json_encode($result));
        }

        $sql = $mysql->query("select * from dyspw_member where  id != {$id} and username = '{$params['username']}'");
        $member = $sql->fetch_all(MYSQLI_ASSOC);
        // print_r($params);exit;
        // if(!empty($member)){
        //     $result['status'] = 'n';
        //     $result['info'] = '此用户名称已存在，请重新输入';
        //     exit(json_encode($result));
        // }
        if($is_vip == 3 || !empty($invite_code)){
            $member_up = $mysql->query("UPDATE dyspw_member SET avatar='{$params['avatar']}',sort='{$params['sort']}', username='{$params['username']}', intro='{$params['intro']}', shop_add='{$params['shop_add']}', shop_lng='{$params['shop_lng']}',
                shop_lat='{$params['shop_lat']}', shop_spot='{$params['shop_spot']}', mobile='{$params['mobile']}', qq_email='{$params['qq_email']}',is_vip=3
                , shop_doorway='{$params['shop_doorway']}', shop_images='{$params['shop_images']}', shop_bank_add='{$params['shop_bank_add']}',invite_code='$invite_code'
                , shop_spot_ratio='{$params['shop_spot_ratio']}', praise_num='{$params['praise_num']}', praise_img='{$params['praise_img']}', praise_award='{$params['praise_award']}'
                , shop_yyzz='{$params['shop_yyzz']}',shop_hygiene='{$params['shop_hygiene']}',shop_bank='{$params['shop_bank']}',shop_just='{$params['shop_just']}',shop_back='{$params['shop_back']}', wx_img='{$params['wx_img']}' where id={$id}");
        }else{
            $member_up = $mysql->query("UPDATE dyspw_member SET avatar='{$params['avatar']}',sort='{$params['sort']}', username='{$params['username']}', intro='{$params['intro']}',mobile='{$params['mobile']}', wx_img='{$params['wx_img']}' where id={$id}");
        }
        $is_vip == 3 ? $role = '商户' : $role = '个人';
        if($member_up){
            // if(!empty($invite_code)){
            //     //商户填写提交做是否有邀请码判定，若有邀请码直接为邀请业务员，业务员父级，业务员祖级增加可提现预计提现，可提现详情信息
            //     $time = time();
            //     $sale_sql = $mysql->query("select * from dyspw_salesman where invite_code = '{$invite_code}'");
            //     $sale = $sale_sql->fetch_all(MYSQLI_ASSOC);
    		// 	if($sale[0]['parent_id'] != 0){
    		// 		//父级id不为空时给父级id添加分账
    		// 		$info = $sale[0]['u_name'].'邀请'.$params['username'].'店铺入驻';
    		// 		$mysql->query("INSERT INTO dyspw_sale_cash (s_id, s_money, info, `time`) VALUES ({$sale[0]['parent_id']},30,'$info',$time)");
    		// 		$mysql->query("UPDATE dyspw_salesman SET cash = cash+30, expect_cash = expect_cash+300 WHERE `id`={$sale[0]['parent_id']}");
    		// 	}
    		// 	if($sale[0]['forbears_id'] != 0){
    		// 		$info = $sale[0]['u_name'].'邀请'.$params['username'].'店铺入驻';
    		// 		$mysql->query("INSERT INTO dyspw_sale_cash (s_id, s_money, info, `time`) VALUES ({$sale[0]['forbears_id']},20,'$info',$time)");
    		// 		$mysql->query("UPDATE dyspw_salesman SET cash = cash+20, expect_cash = expect_cash+200 WHERE `id`={$sale[0]['forbears_id']}");
    		// 	}
    		// 	$info = '邀请'.$member['u_name'].'店铺入驻';
    		// 	$mysql->query("INSERT INTO dyspw_sale_cash (s_id, s_money, info, `time`) VALUES ({$sale[0]['id']},100,'$info',$time)");
    		// 	$mysql->query("UPDATE dyspw_salesman SET cash = cash+100, expect_cash = expect_cash+1000 WHERE `id`={$sale[0]['id']}");
            // }
            $result['status'] = 'y';
            $result['info'] = $role.'编辑成功,即将跳转';
            exit(json_encode($result));
        }else{
            $result['status'] = 'n';
            $result['info'] = $role.'编辑失败，请重新提交';
            exit(json_encode($result));
        }
    }
 ?>
